import Vue from 'vue'
import App from './App.vue'
import '@/assets/css/bootstrap.css'

// 1.导入 Vuex模块
import Vuex from 'vuex'

// 2.给Vue装插件
Vue.use(Vuex)
// 3.创建store 的实例对象
const store = new Vuex.Store({
  // Vue的配置对象
  state: {
    count: 0,
    name: 'biubiu',
    list: [
      { id: 100, name: '吃饭', isDone: true },
      { id: 101, name: '睡觉', isDone: false },
      { id: 102, name: '打豆豆', isDone: true }
    ]
  },
  mutations: {
    add(state, obj) {
      state.count += obj.num
      console.log(obj.name)
    }
  },
  actions: {
    suAsync(context) {
      setTimeout(() => {
        context.commit('add', { num: -5 })
      }, 1000)
    }
  },
  getters: {
    isAll(state) {
      return state.list.every((item) => item.isDone)
    }
  }
})

Vue.config.productionTip = false

new Vue({
  render: (h) => h(App),
  store
}).$mount('#app')
